/*******************************************************************
 *
 * Copyright (C), 2021-2022, Letstrong, All rights reserved.
 *
 * Author      : 
 * Create Time : 2020-12-14
 * Version     : v0.1
 * Description : 
 *******************************************************************/
 
/*----------------------------Head file----------------------------*/
#include "wm.h"
#include "string.h"
#include "app_display.h"
#include "app_global_data.h"

/*----------------------------macro file---------------------------*/

/*----------------------------type define--------------------------*/

/*----------------------------var define---------------------------*/
wm_t wm;

/*-------------------------func declaration------------------------*/

/*-----------------------------------------------------------------*/

void wm_set_disp_off_cnt(uint16_t cnt)
{
	wm.disp_off_cnt = cnt;
}

void wm_set_backlight_off_cnt(uint16_t cnt)
{
	wm.backlight_off_cnt = cnt;
}

void wm_set_cur_win(uint8_t cur_win)
{
	wm.cur_win = cur_win;
}

uint8_t wm_get_cur_win(void)
{
	return wm.cur_win;
}

uint8_t wm_get_revert_win(void)
{
    return wm.revert_win;
}

void wm_info_set(wm_t* info)
{
	uint8_t temp_win;
	if(NO_WIN == info->cur_win) {
		temp_win = wm.cur_win;
	}
	
	info->disp_off_cnt = info->disp_off_cnt;
	info->backlight_off_cnt = BACKLIGHT_OFF_CNT;
	wm = *info;
	
	if(NO_WIN == info->cur_win) {
		wm.cur_win = temp_win;
	}
	g_app_data.disp.tim_cnt = 0;
}

void wm_disp_off_and_bl_cnt_reset(void)
{
	wm.disp_off_cnt = DEFAULT_DISP_OFF_CNT;
	wm.backlight_off_cnt = BACKLIGHT_OFF_CNT;
	app_disp_backlight_set(true);
}

void wm_disp_off_and_bl_cnt_reset_ex(void)
{
	wm.disp_off_cnt = DEFAULT_DISP_OFF_CNT;
	wm.backlight_off_cnt = BACKLIGHT_OFF_CNT;
}

void wm_charge_bl_off_cnt_reset(void)
{
	wm.backlight_off_cnt = BACKLIGHT_OFF_CNT;
	app_disp_backlight_set(true);
}


void wm_disp_off_cnt_reset(void)
{
	wm.disp_off_cnt = DEFAULT_DISP_OFF_CNT;
}

void wm_set_flash_cnt_down(void)
{
	wm.flash_cnt_down = DEFAULT_UI_FLASH_CNT;
}

void wm_full_disp(void)
{
	wm_t wm;

	memset((uint8_t*)&wm, 0, sizeof(wm));
	wm.cur_win = FULL_DISP_WIN;
	wm.disp_off_cnt = FULL_DISP_CNT;

	wm_info_set(&wm);
	app_disp_all_pixel();
	app_disp_update();
}
